/*
n a[] k[]
每次最多可前进[i+1, min(n,i+k[i])]-a[i];

bfs():
    邻接保存可以一次跳到的点
        for(int u=1; u<=n; u++)
            for(int v=u+1; v<=min(n,u+k[u]); v++)
                AddEdge(u, v-a[v])
答案即为终点与起点之间的层数
*/
// #include <cstdio>
#include <iostream>
#include <cstring>
#include <queue>
using namespace std;
#define DEBUG
using ll=long long;
inline int read()
{
    int c=getchar(), f=1, x=0;
    if(c=='-') f*=-1, x=getchar();
    while(c<'0'&&'9'<c) c=getchar();
    while('0'<=c&&c<='9') 
        x=(x<<3)+(x<<1)+c-'0', c=getchar();
    return f*x;
}
inline void write(long long x)
{
    if(x>=10) write(x/10);
    putchar(x%10+'0');
}
const int N=1e5+10, INF=0x3f3f3f3f;
using PII=pair<int, int>;
#define ste first
#define pos second
int n;
int a[N], k[N], dest[N];
bool st[N];
int dep[N];
int scope=1; //探索的最远范围

void init()
{
    memset(dep, 0x3f, sizeof dep);

    n=read();
    for(int i=1; i<=n; i++)
        a[i]=read(), dest[i]=i-a[i];
    for(int i=1; i<=n; i++)
        k[i]=read();

}

void bfs()
{
    priority_queue<PII,vector<PII>, greater<PII>> q;

    q.push({0, 1});
    dep[1]=0;

    while(q.size())
    {
        int u=q.top().pos, step=q.top().ste; q.pop();

        if(step>dep[u]) continue; //不可更新
        for(int v=max(u,scope)+1; v<=min(u+k[u], n); v++)
        {
            int to=dest[v]; scope=max(v, scope);
            if(dep[to]>step+1) //可以更新
            {
                dep[to]=step+1;
                q.push({step+1, to});
            }            
        }
    }
}

void solve()
{
    init();
    bfs();
    printf("%d\n", dep[n]==INF?-1:dep[n]);
}

signed main()
{
    #ifdef DEBUG
        freopen("../in.txt", "r", stdin);
        // freopen("../out.txt", "w", stdout);
    #endif

    int T=1; //cin >> T; 
    while(T--) 
    {
        solve();
    }
    return 0;
}
